package day05;

import java.util.Random;

public class MethodDemo2 {
    //有参有返回值的方法
    public static void main(String[] args) {
        int sum = add(10,20);
        System.out.println(sum);

        int m = 5, n = 10;
        int a = m + n;
        System.out.println(a);
        System.out.println("================");

        int[] arr = createArray(10, 100);//模拟返回值后续操作。

        int[] b = createArray(10, 100);
        System.out.println("数组的长度是" + b.length);
        for(int i = 0; i < b.length; i++){
            System.out.println(b[i]);
        }
    }

    //生成一个有返回值的随机数组
    public static int[] createArray(int len, int max){
        Random rand = new Random();
        int[] arr = new int[len];
        for(int i = 0; i < arr.length; i++){
            //arr[i] = (int)(Math.random()*(max + 1));
            arr[i] = rand.nextInt(max + 1); //上下原理相同
        }
        return arr;
    }

    public static int add(int a, int b){
        int add = a+b;
        return add;
    }
}
